/*****************************************************************
**                                                              **
**  Copyright (C) 2004 Amlogic,Inc.                             **
**  All rights reserved                                         **
**        Revision : 1.0                                        **
**                                                              **
*****************************************************************/
#include "includes.h"
#include "aw_windows.h"
#include <aw_playlist2.h>
#include "../user.h"
#include "app.h"
#include "t_filelist.h"
#include "gplayer_app.h"
#include "aw_gui_app.h"
#include "aw_PIC_app.h"
#include "aw_GPLAYER_app.h"
#include "aw_sys_app.h"
#include "aw_config.h"
#include "logoevent.h"
#include "filelistevent.h"
#include "logo_dat.h"
#include "aw_init_display.h"
#include "../fs_playlist.h"
#include "ctrlconvert.h"
#include "MoviePlayBackEvent.h"
#include "WinConfirmEvent.h"
#include "DeviceSelectEvent.h"
#include "scrsaver.h"
#define GPLAYER_STATUS_RUNNING    0
#define GPLAYER_STATUS_QUITTING   1
#define GPLAYER_STATUS_SWITCHING  2
#define GPLAYER_STATUS_SKIPPING   3

#define GPLAYER_UNKNOW	0
#define GPLAYER_AUDIO		1
#define GPLAYER_VIDEO 		2

#define UOP_GETMP3INFO 200
#define UOP_GETMP3ID3 201

#ifdef ENABLE_BLUETOOTH
 extern unsigned char bt_play_flag;
#endif

extern INT32U NODIR_FLAG;  //0 for with dir, 1 for playing music without dir, 2 for playing video without dir.
void AWGPlayerKeyDo(INT32S key) ;

Playlist_t *gplayer_playlist;
AUDIO_STREAM_INFO pInfo;

static int gplayer_type = GPLAYER_UNKNOW;
static PlaylistItem_t *gplayer_playitem;
static char last_item_name[150]= {0};
static char device_removed=0;
static char gplayer_processing_status = GPLAYER_STATUS_QUITTING;
static INT8U ff_level ,fb_level ;
static INT32U gplayer_playing_time = 0xffffffff;
static unsigned fast_play_time=5; /* unit: 0.1s; 0: fast forward/backward without playing sound*/
static unsigned load_gplayer_data[10];
static VIDEO_STATUS_t gplayer_state_flag = VIDEO_STOP_PLAY;

char record_resume_file[256];
INT16U AudioStatus = 0;
int spectrum[32];
INT8U GetNextOrPrev ;

extern unsigned char user_power_flag;
extern char gCurOnlyMp3FileName[256] ;
extern int preview_video;
extern INT8U CurrentOsdSize ;
extern INT8U isMute ;
extern INT8U FileListOnShowFlag;
extern INT8U  Music_Pic_mix_flag ;
extern INT16U Mp3PlayStatus ;
extern INT8U LogoResum ;
extern INT8U PlayBackResume ;
extern INT8U PlayBackHome ;
extern INT8U LogoHome ;
extern unsigned char Volume_Value;
#if  HOTKEYENABLE
extern char hotkey_flag ;
#endif

extern INT32U last_hotkey ;
extern FILEINFO file_info_onshow;
#ifdef TIME_SEARCH
extern INT32S search_time_hour ;
extern INT32S search_time_min ;
extern INT32S search_time_sec  ;
#endif
#ifdef ZOOM_IN
extern int reduce_level;
#endif
#ifdef RESUME_PLAY
extern RESUME_FILEINFO resume_file;
extern INT8U ResumePlayFlag;
extern INT8U ResumeFunction;
static INT8U movResumePlay = 0;
static unsigned long resumetime = 0;
#endif

void GetMOVInfo(char *file_name, VIDEO_INFO *mov_info)
{
	stream_t* stream = NULL;
	int file_format = DEMUXER_TYPE_UNKNOWN;
	int total_time;
	unsigned config[2];
	int fd;
	struct stat stat_buf;
	
	config[0] = (unsigned)file_name;
	config[1] = 0;


	gplayer_t *gGPlayerArg_;
	gGPlayerArg_ = (gplayer_t *)AVMem_malloc(sizeof(gplayer_t));

	file_format=demuxer_type_by_filename((char*)file_name);
	if (DEMUXER_TYPE_MOV == file_format){
		//stream = (stream_t *)AVMem_malloc(sizeof(stream_t));
		//demuxer = (demuxer_t *)AVMem_malloc(sizeof(demuxer_t));
		gGPlayerArg_->play.demuxer = 0;
		
		file_format = DEMUXER_TYPE_UNKNOWN;	
		demux_register_mov();

		gGPlayerArg_->play.stream = open_stream((char*)file_name, (char **)0, &file_format);
		if(gGPlayerArg_->play.stream){
			file_format=demuxer_type_by_filename((char*)file_name);
			gGPlayerArg_->play.demuxer = demux_open(gGPlayerArg_->play.stream,file_format, -1, -1, -1, (char *)config);
			if(gGPlayerArg_->play.demuxer==0){
				free_stream(gGPlayerArg_->play.stream);
				mov_info->audio_type = AUDIO_TYPE_UNKNOW;
				mov_info->video_type = VIDEO_TYPE_UNKNOW;
				mov_info->total_time = 0;
				fd=open(file_name,O_RDONLY);
				if(fd>=0){
					fstat(fd,&stat_buf);
					mov_info->size = stat_buf.st_size; 
					close(fd);
				}
				AVMem_free(gGPlayerArg_);
				return;
			}
		}
		demux_control(gGPlayerArg_->play.demuxer,DEMUXER_CTRL_GET_TIME_LENGTH, &total_time);	
		gGPlayerArg_->play.d_audio=gGPlayerArg_->play.demuxer->audio;
		gGPlayerArg_->play.d_video=gGPlayerArg_->play.demuxer->video;
		gGPlayerArg_->play.sh_audio=gGPlayerArg_->play.d_audio->sh;
		gGPlayerArg_->play.sh_video=gGPlayerArg_->play.d_video->sh;
		mov_info->audio_type = gGPlayerArg_->play.sh_audio->format;
		mov_info->video_type = gGPlayerArg_->play.sh_video->format;
		mov_info->total_time = total_time;
              free_stream(gGPlayerArg_->play.stream);
	//	demux_uninit(gGPlayerArg_->play.demuxer);
		//demux_uninit(demuxer);	
		fd=open(file_name,O_RDONLY);
		if(fd>=0){
			fstat(fd,&stat_buf);
			mov_info->size = stat_buf.st_size; 
			close(fd);
		}
	}
	AVMem_free(gGPlayerArg_);
}


static void UpdateGplayerStatus(PCMDSET pCmd)
{
	switch(pCmd->commands[0])
	{
		case CM_LOAD_APP:
		case CM_PLAY:
//    			ff_level = fb_level = 1 ;
		 	gplayer_state_flag=VIDEO_NORMAL_PLAY;
		 	break;
		case CM_PAUSE:
//		 	fb_level=1;     
//			ff_level=1;   
		 	gplayer_state_flag=VIDEO_PAUSE_PLAY;
		 	break;
		case CM_QUIT:
		case CM_STOP:
		 	gplayer_state_flag=VIDEO_STOP_PLAY;
			
		 	break;
		case CM_BACKWARD_SCAN:
			gplayer_state_flag = VIDEO_FB1_PLAY;
	              break;			
	        case CM_FORWARD_SCAN:
			gplayer_state_flag = VIDEO_FF1_PLAY;
			default:
		     	break;
	}
}

char *GPlayerGetCurrentPlayingName()
{
    PlaylistItem_t * pl;
    pl=AWGetCurrentPlaylistItem2(gplayer_playlist);
    if(pl){
        return pl->location;   
    }    
    else
        return NULL;
}

static void send_gplayer_quit(void)
{
    INT8U my_app_id ;
    INT16U pCmds = CM_QUIT;
    INT32U pCmdsParam = 0;
    INT8U pCmdTimeOut = 0;

    AWGetAppID(MEDIA_GENERAL, &my_app_id) ; 
    AWAddCmdSet(1, &pCmds, &pCmdsParam, &pCmdTimeOut, 
                my_app_id, GPlayerPlayCmdResponse) ;
}

/* Callback from the playlist module when the next
 * playlist item has been retrieved. */
static void GPlayerPlaylistCb(Playlist_t *playlist, 
                              PlaylistItem_t *item,
                              PlaylistStatus_t status)
{
    PAPPTASKARG pGPLAYERAppArg;

    if(status == PLAYLIST_STATUS_OK) {
        if((GetAppType(item->location) == MEDIA_OTHER) ||(GetAppType(item->location) == MEDIA_NULL)){
            pGPLAYERAppArg = AWGetAppArg(MEDIA_GENERAL) ;	
            AWAppSendMessage(pGPLAYERAppArg->app_id, pGPLAYERAppArg->aw_msg_q,  pGPLAYERAppArg->aw_event_handle,
                             MSG_NOTIFICATION, NM_GET_NEXT, 0) ;
            return ;
        }
        if(GetAppType(item->location) != MEDIA_GENERAL) {
        	gplayer_processing_status = GPLAYER_STATUS_SWITCHING;
        	send_gplayer_quit();
        	gplayer_playlist = playlist;
        	gplayer_playitem = item;
        }
        else {
            AWLockPlaylist(playlist);
            AWGUISendNMMessage(GetAppType(item->location), NM_PLAY_GENERAL, (INT32U)playlist) ;
        }
    }
    else 
	if((status == PLAYLIST_STATUS_GET_NEXT) ||(status == PLAYLIST_STATUS_GET_PREV)){
            pGPLAYERAppArg = AWGetAppArg(MEDIA_GENERAL) ;
            AWAppSendMessage(pGPLAYERAppArg->app_id, pGPLAYERAppArg->aw_msg_q,  pGPLAYERAppArg->aw_event_handle,
                             MSG_NOTIFICATION, ((status == PLAYLIST_STATUS_GET_NEXT) ? NM_GET_NEXT : NM_GET_PREV), 0) ;
            return ;
    }
    else {
        AWGUISendNMMessage(MEDIA_GENERAL, NM_PLAY_GPLAYER, 0);
    }
}

int RunGPlayer(Playlist_t *playlist)
{
    int r = 0;
    INT8U my_app_id ;
    INT32U item_type;


    if(gplayer_playlist) {
        if(AWPlaylistDelete2(gplayer_playlist) == 0) {
            gplayer_playlist = NULL;
        }
    }

    AWGetAppID(MEDIA_GENERAL, &my_app_id) ; 
    if (AWGetAppStatus(my_app_id) != APP_RUNNING) {
        AWSetPlaylistAppCb(playlist, GPlayerPlaylistCb);
        gplayer_playlist = playlist;
        if((gplayer_playitem = AWGetCurrentPlaylistItem2(playlist)) == NULL) {
            if(AWGetStartPlaylistItem2(playlist) != PLAYLIST_STATUS_ASYNCH) {
                gplayer_playlist = NULL;
                return -1 ;
            }
        }
        item_type = GetMediaType(gplayer_playlist->cur_play_item->item.location) ;
        if (item_type&AW_AUDIO_LIST){
            gplayer_type = GPLAYER_AUDIO;
        }
        else if (item_type == MEDIA_MOV) {
            gplayer_type = GPLAYER_VIDEO;
        }
        else {
            gplayer_type = GPLAYER_UNKNOW;
            return -1;
        }
		
        String_Init_Time();

	    if(isMute) {// unMute
	    	GPIO_MB_UNMUTE ;
	    }
	    else {
	    	GPIO_MB_MUTE ;
	    }

        
        if ((gplayer_type == GPLAYER_VIDEO) && (preview_video == 0))
            ShowWinMoviePlayBack();

        AWAppRunning(my_app_id) ;
        gplayer_processing_status = GPLAYER_STATUS_RUNNING;
    } else {
        send_gplayer_quit();
        gplayer_playlist = NULL;
        return -1;
    }

	if(gplayer_type == GPLAYER_AUDIO){
		
		if(GetMusicRepeatModePara() == (INT8U)0){
			if(NODIR_FLAG==0)
				AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_ONLYONE);
			else
				AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_REPEAT_ONE);
			}
		else 
		if(GetMusicRepeatModePara() == 1){
			if(NODIR_FLAG==0)
				AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_ONLYONE);
			else
				AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_DIR_REPEAT);
		}
	}
	else {
		if(GetMovieRepeatModePara() == (INT8U)0){
			if(NODIR_FLAG==0)
				AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_ONLYONE);
			else if(NODIR_FLAG==2)
				AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_REPEAT_ONE);
		}		
		else 
		if(GetMovieRepeatModePara() == (INT8U)1){
			if(NODIR_FLAG==0)
				AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_ONLYONE);
			else if(NODIR_FLAG==2)
				AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_DIR_REPEAT);
		}
	}

    return 0;
}

INT8U GPlayerPlayCmdResponse(AWMSG *pMsg, PCMDSET cmd_set)
{
    INT8U iRet = BREAK_EXECUTE_COMMAND ;

    switch(pMsg->msg_type){
        case MSG_COMMAND_SUCCESS:
            if (NODIR_FLAG==1) {			
                if(cmd_set->commands[0] == CM_PLAY) {
                    GPIO_UNMUTE;
//                    UpdateMusicPlayInfoControl(GPLAYER_PLAY, 0, 0, -1) ;
                }
            }
            else if (NODIR_FLAG==2){
                UpdateGplayerStatus(cmd_set);     
            }
        #ifdef RESUME_PLAY	
            INT8U my_app_id ;
            INT16U pCmds;
            INT32U pCmdsParam ;
            INT8U pCmdTimeOut = 2 ;

			if(cmd_set->commands[0] == CM_PLAY) 
			{

                AWGetAppID(MEDIA_GENERAL, &my_app_id) ; 
                if((ResumePlayFlag == 1)&&(gplayer_type == GPLAYER_VIDEO)&&(resume_file.time))
                {
                    pCmds = CM_TIME_SEARCH;
                    pCmdsParam = resume_file.time ;
                    AWAddCmdSet(1, &pCmds, &pCmdsParam, &pCmdTimeOut, my_app_id ,GPlayerPlayCmdResponse) ;	
                }
			}
	    #endif
            iRet = GO_ON_EXECUTE_COMMAND ;
            break ;
        case MSG_COMMAND_FAIL:
	     UpdateIsProcessBarOnShowValue();
//	     AWGPLAYERQuitProcess();
	     if((NODIR_FLAG==1)&&(gplayer_type == GPLAYER_AUDIO))
	     AWGPlayerKeyDo(UOP_NEXT_CHAP) ;
            iRet = GO_ON_EXECUTE_COMMAND ;
            break ;
        case MSG_COMMAND_FORBIDEN:
            break ;
        case MSG_COMMAND_NOT_SUPPORT:
            default:
            break ;
    }
    return iRet ;
}

static void send_gplayer_stop(void)
{
    INT8U my_app_id ;
    INT16U pCmds = CM_STOP;
    INT32U pCmdsParam = 0;
    INT8U pCmdTimeOut = 0;

    AWGetAppID(MEDIA_GENERAL, &my_app_id) ; 
    AWAddCmdSet(1, &pCmds, &pCmdsParam, 
                &pCmdTimeOut, my_app_id, GPlayerPlayCmdResponse) ;
}

// static unsigned load_gplayer_data[5];

void send_gplayer_file(char *file_name)
{
    PCMDSET pCmd ;
    INT8U my_app_id ;
    INT32U item_type;

    gplayer_playing_time=0xffffffff;
    ff_level = fb_level = 1 ;

    AWGetAppID(MEDIA_GENERAL, &my_app_id) ; 

    item_type = GetMediaType(file_name) ;
        if (item_type&AW_AUDIO_LIST){
        gplayer_type	= GPLAYER_AUDIO;
        }
    else if (item_type == MEDIA_MOV)
        gplayer_type	= GPLAYER_VIDEO;
    else
        gplayer_type	= GPLAYER_UNKNOW;
			
    pCmd = AWCommandSetMalloc();
    if (pCmd) {
        pCmd->command_num = 1;
        pCmd->curr_executed_cmd_num = 0;
        pCmd->commands[0] = CM_PLAY;
        pCmd->commands_para[0] = (INT32U)load_gplayer_data;

        load_gplayer_data[0] = (unsigned)file_name;
        load_gplayer_data[1] = 0;
        load_gplayer_data[2] = 0;
        load_gplayer_data[3] = 0;
        load_gplayer_data[4] = 0;
        load_gplayer_data[5] = 0;		
        if(preview_video)
        {
            unsigned short start_x=336, start_y=86, width=360, height=240, preview_flag=1, audio_mute=1;
            unsigned char video_mode = DISPCTL_MODE_480I;        
            switch (CurrentOsdSize){
                case OsdSize480i:
                case OsdSize480iCVBS:					
                    video_mode = DISPCTL_MODE_480I;
                    break;
                case OsdSize480p:
                    video_mode = DISPCTL_MODE_480P;
                    break;
		#ifdef SUPPORT_VGA				
                case OsdSizeVga:
                	start_x += (WinStart_x-60);
                	start_y += (WinStart_y-30);	
                	width = 480 ;
                	height = 300 ;						
                    video_mode = DISPCTL_MODE_VGA;
                    break;		
		#endif
                case OsdSize576i:
                case OsdSize576iCVBS:					
                    start_y=86+48;
                    video_mode = DISPCTL_MODE_576I;
                    break;
                case OsdSize576p:
                    start_y=86+48;
                    video_mode = DISPCTL_MODE_576P;					
                    break;
                case OsdSize720p:
                	start_x = 700;
                	start_y = 152;
                	width = 500 ;
                	height = 282 ;					
                     video_mode = DISPCTL_MODE_720P;
                     break;					 
                default:
		#ifdef WISTAR_VERSION
                    video_mode = DISPCTL_MODE_480P;					
		#else		
                    video_mode = DISPCTL_MODE_480I;					
		#endif
                    break;
            }
            load_gplayer_data[5] |= 0x20000;
            load_gplayer_data[6] = start_y | (start_x<<16);
            load_gplayer_data[7] = width | (height<<16);
            load_gplayer_data[8] = preview_flag | (audio_mute<<1)|(video_mode<<24);
            strcpy(last_item_name, file_name);			
        }		
        else {
            load_gplayer_data[5] = 0;
            load_gplayer_data[6] = 0;
            load_gplayer_data[7] = 0;
            load_gplayer_data[8] = 0;
            memset(last_item_name, 0, 150);			
        }			
        //pCmd->cmd_timeout_value[0] = 5; 
        if (gplayer_type	== GPLAYER_VIDEO)
            load_gplayer_data[5] |= 0x8;
        INT8U pic_app_id ;
        if (AWGetAppID(MEDIA_PIC, &pic_app_id) == 0){
    		if (AWGetAppStatus(pic_app_id) == APP_RUNNING){
    		    load_gplayer_data[5] |= 0x8;
    		}	
	    }
        pCmd->app_id = my_app_id ;
        pCmd->ExecuteResultProcess = GPlayerPlayCmdResponse;
        AWAddCommandSet(pCmd);
//        UpdateMusicPlayFileName(file_name) ;

		
    }
}


int PreviewGPlayer(char *filename)
{
    INT8U my_app_id ;
    AWGetAppID(MEDIA_GENERAL, &my_app_id) ; 
    
    if (AWGetAppStatus(my_app_id) != APP_RUNNING) 
    {
        AWAppRunning(my_app_id) ;
        gplayer_processing_status = GPLAYER_STATUS_RUNNING;
        if (preview_video == 0)
            ShowWinMoviePlayBack();
        send_gplayer_file(filename);
    }
    else 
    {
    	send_gplayer_quit();
        return -1;
    }
    return 0;
}

void gplayer_play_preview(char *filename) 
{
	send_gplayer_stop();
       ShowWinMoviePlayBack();
	send_gplayer_file(filename);
}

void AWGPLAYERQuitProcess(void) 
{
    gplayer_processing_status = GPLAYER_STATUS_QUITTING;
    send_gplayer_quit();
//    if((NODIR_FLAG==0)&&(gplayer_type == GPLAYER_VIDEO)){
//		AWShowFileList(1);
//	}
    //gplayer_type	= GPLAYER_UNKNOW;
    if ((INT32U ) &pInfo){
        //AVMem_free(pInfo);
        //pInfo = NULL;
    }
    if(gplayer_playlist) {
        AWPlaylistDelete2(gplayer_playlist);

        gplayer_playlist = NULL;
    }
#ifdef USE_NEW_SCREEN_SAVER 
    screensaverstop(0);
    ScrSaverSet(SCREEN_SAVER_ON) ;
    ScrSaverReset() ;
#else
    if(gScreenSaveFlag &&(keytimer)&&(!AVTimerIsEnabled(keytimer)) && !(Music_Pic_mix_flag)){
        screensaverstop(0);
        AVTimerEnable(keytimer);
    }    
#endif

    if(device_removed){
        device_removed=0;
        return;
    } 

}


void AWGPLAYERQuitProcess2(AWMSG *pMsg) 
{
#ifdef RESUME_PLAY
    if((gplayer_type == GPLAYER_VIDEO)&&(ResumeFunction == 1))
    {
        ResumePlayFlag = 0;
    #ifdef SUPPORT_STANDBY
        extern char iPowerFlag;
        if(iPowerFlag == 0)
    #endif
        {
    	    resume_file.time = 0;
    	    SetResumePlayFlagPara(0);
    	}
    #ifdef SUPPORT_STANDBY
    	else
    	{
        #if RESUME_INTERVAL_TIME
        //
        #else
            SetResumePlayFlagPara(1);
        #endif
            SetResumeTimePara(resume_file.time);
    	}
    #endif
    }
#endif
	if(user_power_flag)
			return;
#if HOTKEYENABLE
	if((hotkey_flag)&&(!Music_Pic_mix_flag)){
		ReloadLogo();
		APPHotKeyProcess(&last_hotkey);
		hotkey_flag = 0 ;
		return ;
	}
#endif

    gplayer_state_flag=VIDEO_STOP_PLAY; 
    if(gplayer_processing_status == GPLAYER_STATUS_SWITCHING) {
        AWLockPlaylist(gplayer_playlist);
        AWGUISendNMMessage(GetAppType(gplayer_playitem->location), NM_PLAY_GENERAL, (INT32U)gplayer_playlist) ;
        gplayer_playlist = NULL;
    }

	if((preview_video == 1)&&(NODIR_FLAG == 2)){  // Preview Quit
		Update_Video_PreviewScreen_Screen(0);
		disable_video_layer();
	}
	else if(gplayer_type == GPLAYER_VIDEO)
	{
	    GUIHideWindow(WinMoviePlayBack) ;
	}
	if(LogoResum == 1){
        if(gplayer_type == GPLAYER_VIDEO)
		    ReloadLogo();
		ResumFromLogo();
		LogoResum = 0 ;
	}
	else if(PlayBackResume == 1){    // MoviePlay Quit 
		ReloadLogo();
		ResumFromMoviePlayBack();
		PlayBackResume = 0 ;

	} 
	else if(PlayBackHome == 1){
		ReloadLogo();
		GUIShowWindow(WinDeviceSelect);
		PlayBackHome = 0 ;
	}
	else if(LogoHome == 1){
		ReloadLogo();
		GUIShowWindow(WinDeviceSelect);
		LogoHome = 0 ;
	}	
	else {
		
		if((NODIR_FLAG == 0)&&(gplayer_type == GPLAYER_VIDEO)){
			ReloadLogo();
			GUIShowWindow(WinFileList);
		}
		else {
			
			if((preview_video == 1)&&(NODIR_FLAG == 2)){
				preview_video = 0 ;
			}
			/*
			else {
				if(NODIR_FLAG == 2){
					ReloadLogo();
					GUIShowWindow(WinLogo);
				}
			}
			*/
		}
	}

	gplayer_type = GPLAYER_UNKNOW;
    return;
}

void AWGPlayerKeyDo(INT32S key)
{
    INT8U my_app_id ;
    INT16U pCmds;
    INT32U pCmdsParam ;
    INT8U pCmdTimeOut = 2 ;
    unsigned fast_skip_time;

	if((preview_video==1) && (key!=UOP_STOP))
       return;	
       
    AWGetAppID(MEDIA_GENERAL, &my_app_id) ; 
    
#ifdef KOREAR_REMOTE
	switch(key){
		case UOP_UP:
			key = UOP_PREVIOUS_CHAP;
			break;
		case UOP_DOWN:
			key = UOP_NEXT_CHAP;
			break;
		case UOP_LEFT:
			key = UOP_FAST_BACKWARD;
			break;
		case UOP_RIGHT:
			key = UOP_FAST_FORWARD;
			break;
		}
#endif
	switch(key){
		case UOP_GETMP3INFO:	
			pCmds = CM_GET_PLAYING_AUDIO_INFO;
			if ((INT32U ) &pInfo){
				//AVMem_free(pInfo);
				//pInfo = NULL;
			}
			//pInfo = (AUDIO_STREAM_INFO *)AVMem_malloc(sizeof(AUDIO_STREAM_INFO));
			pCmdsParam = (INT32U ) &pInfo;
			if((INT32U ) &pInfo)	 
				AWAddCmdSet(1, &pCmds, &pCmdsParam, &pCmdTimeOut, my_app_id ,GPlayerPlayCmdResponse) ;
			break;
    	
		case UOP_GETMP3ID3:	
			pCmds = CM_GET_PLAYING_AUDIO_INFO;
			//pInfo = (AUDIO_STREAM_INFO *)AVMem_malloc(sizeof(AUDIO_STREAM_INFO));
			pCmdsParam = (INT32U )& pInfo;
			if((INT32U ) &pInfo)	 
				AWAddCmdSet(1, &pCmds, &pCmdsParam, &pCmdTimeOut, my_app_id ,GPlayerPlayCmdResponse) ;	
			break;
    		
		case UOP_RESUME:
		case UOP_1:
			if (NODIR_FLAG==2)
			{
				AWGPLAYERQuitProcess();
			}
			else if((NODIR_FLAG==0)&&(gplayer_type == GPLAYER_VIDEO))
			{
				AWGPLAYERQuitProcess();
//				GUIShowWindow(WinFileList);
			}
			else if(Music_Pic_mix_flag)
			{
				AWGPLAYERQuitProcess();
			}
			else
			{
				pCmds = CM_VOLUME_UP;
				pCmdsParam = 0 ;
				//pCmdTimeOut = 2 ;
				AWAddCmdSet(1, &pCmds, &pCmdsParam, &pCmdTimeOut, my_app_id ,GPlayerPlayCmdResponse) ;
			}    
		 	break;
		 	
		case UOP_2:
			pCmds = CM_VOLUME_DOWN;
			pCmdsParam = 0 ;
			//pCmdTimeOut = 2 ;
			AWAddCmdSet(1, &pCmds, &pCmdsParam, &pCmdTimeOut, my_app_id ,GPlayerPlayCmdResponse) ;
			break;
	
		case UOP_4:
			char *tmp_location = AWGetCurrentPlaylistItem2(gplayer_playlist)->location;	 
			int tmp_size = strlen(tmp_location);
			if (!(memcmp(&record_resume_file, tmp_location, tmp_size)))
			{
				 pCmds = CM_RESUME_PLAY;
			        pCmdsParam = 0 ;
			        AWAddCmdSet(1, &pCmds, &pCmdsParam, &pCmdTimeOut, my_app_id ,GPlayerPlayCmdResponse) ;
			}
			else
			{
				goto COMMAND_PLAY;
			}
			break;


	    	
		case UOP_STOP:
			AWGPLAYERQuitProcess();
			//if (NODIR_FLAG==2)
				//GUIShowWindow(WinLogo);
			//else 
			//if((NODIR_FLAG==0)&&(gplayer_type == GPLAYER_VIDEO)){
				//GUIShowWindow(WinFileList);
			//}
			break ;
	        
		case UOP_PAUSE:
			pCmds = CM_PAUSE ;
			pCmdsParam = 0 ;
			AWAddCmdSet(1, &pCmds, &pCmdsParam, &pCmdTimeOut, my_app_id, GPlayerPlayCmdResponse) ;
			break ;
        
		case UOP_FAST_BACKWARD:
			if(Music_Pic_mix_flag)
			{
				break;
			}
			
			if(ff_level > 1){
				fb_level = 1 ;
				ff_level-- ;
				if(ff_level == 1)
					goto COMMAND_PLAY ;
			}else if(fb_level <4){
				ff_level = 1 ; 
				fb_level++ ;
			}else {
				goto COMMAND_PLAY;
			}
			
			if(ff_level > 1){
				pCmds = CM_FORWARD_SCAN ;
				fast_skip_time=ff_level*25;
				pCmdsParam = (fast_skip_time<<8)|fast_play_time;  /* fast_skip_time,fast_play_time: unit 0.1s */
				AWAddCmdSet(1, &pCmds, &pCmdsParam, &pCmdTimeOut, my_app_id, GPlayerPlayCmdResponse) ;	
			}else if(fb_level > 1){
				pCmds = CM_BACKWARD_SCAN ;
				fast_skip_time=-((fb_level+1)*25); /* fast_skip_time,fast_play_time: unit 0.1s */
				pCmdsParam = (fast_skip_time<<8)|fast_play_time;
				AWAddCmdSet(1, &pCmds, &pCmdsParam, &pCmdTimeOut, my_app_id, GPlayerPlayCmdResponse) ;
			}	
			break ;
	        
		case UOP_FAST_FORWARD:
			if(Music_Pic_mix_flag)
			{
				break;
			}
			
			if(fb_level > 1)
			{
				ff_level = 1 ;
				fb_level-- ;
				if(fb_level == 1)
					goto COMMAND_PLAY ;
			}
			else if(ff_level <4)
			{
				fb_level = 1 ;
				ff_level++ ;
			}
			else
			{
				goto COMMAND_PLAY;
			}
			
			if(ff_level > 1)
			{
				pCmds = CM_FORWARD_SCAN ;
				fast_skip_time=ff_level*25;
				pCmdsParam = (fast_skip_time<<8)|fast_play_time;  /* fast_skip_time,fast_play_time: unit 0.1s */
				AWAddCmdSet(1, &pCmds, &pCmdsParam, &pCmdTimeOut, my_app_id, GPlayerPlayCmdResponse) ;	
			}
			else if(fb_level > 1)
			{
				pCmds = CM_BACKWARD_SCAN ;
				fast_skip_time=-((fb_level+1)*25); /* fast_skip_time,fast_play_time: unit 0.1s */
				pCmdsParam = (fast_skip_time<<8)|fast_play_time; 
				AWAddCmdSet(1, &pCmds, &pCmdsParam, &pCmdTimeOut, my_app_id, GPlayerPlayCmdResponse) ;
			}	

			break ;
	        
		case UOP_END_PAUSE:
			if(gplayer_state_flag==VIDEO_NORMAL_PLAY)
			{
				pCmds = CM_PAUSE ;
				pCmdsParam = 0 ;
				AWAddCmdSet(1, &pCmds, &pCmdsParam, &pCmdTimeOut, my_app_id, GPlayerPlayCmdResponse) ;
			}
			else
COMMAND_PLAY:
			{
				fb_level=1;     
				ff_level=1;     
				pCmds = CM_PLAY ;
				pCmdsParam = 0 ;
				AWAddCmdSet(1, &pCmds, &pCmdsParam, &pCmdTimeOut, my_app_id, GPlayerPlayCmdResponse) ;
			}
			
#if 0
			pCmds = CM_PLAY ;
			pCmdsParam = 0 ;
			AWAddCmdSet(1, &pCmds, &pCmdsParam, &pCmdTimeOut, my_app_id, GPlayerPlayCmdResponse) ;
			//AudioStatus = AUDIO_PLAY;
#endif
			break ;
        
		case UOP_MUTE:
#if 0		
	        	pCmds = CM_MUTE ;
	        	pCmdsParam = 0 ;
	        	pCmdTimeOut = 2 ;
	        	AWAddCmdSet(1, &pCmds, &pCmdsParam, &pCmdTimeOut, my_app_id ,GPlayerPlayCmdResponse) ;
#endif
			break ;
        	
		case UOP_NEXT_CHAP:
			if(NODIR_FLAG==0)
				break;
			else
			{
				if(gplayer_processing_status != GPLAYER_STATUS_RUNNING)
				{
					break ;
				}
				GetNextOrPrev = MANUAL_GET_NEXT_CHAP;
				gplayer_processing_status = GPLAYER_STATUS_SKIPPING;
				send_gplayer_stop();
				AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_DIR_REPEAT);
				if(AWGetNextPlaylistItem2(gplayer_playlist) != PLAYLIST_STATUS_ASYNCH)
				{
					AWGPLAYERQuitProcess();
				}
				if( (gplayer_type == GPLAYER_VIDEO) && (preview_video == 0)
	        	&& (AWGetTopWindow(gpFocusWin) != AWFindWinCtrlByName(WinMoviePlayBack)) ){
					ShowWinMoviePlayBack();
				}				
				break;
			}
            			
		case UOP_PREVIOUS_CHAP:
			if(NODIR_FLAG==0)
				break;
			else{
				if(gplayer_processing_status != GPLAYER_STATUS_RUNNING) {
					break ;
				}
				GetNextOrPrev = MANUAL_GET_PRE_CHAP;
				gplayer_processing_status = GPLAYER_STATUS_SKIPPING;
				send_gplayer_stop();
	   			AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_DIR_REPEAT);
				if(AWGetPrevPlaylistItem2(gplayer_playlist) != PLAYLIST_STATUS_ASYNCH) {
					AWGPLAYERQuitProcess();
				}
				if( (gplayer_type == GPLAYER_VIDEO) && (preview_video == 0)
	        	&& (AWGetTopWindow(gpFocusWin) != AWFindWinCtrlByName(WinMoviePlayBack)) ){
					ShowWinMoviePlayBack();
				}
				break;
			}
		#ifdef TIME_SEARCH	
		 case UOP_TIME_PLAY:
			INT32S  search_time = (search_time_hour<<16)|(search_time_min<<8)|search_time_sec;
			pCmds = CM_TIME_SEARCH;
			pCmdsParam = search_time ;
			AWAddCmdSet(1, &pCmds, &pCmdsParam, &pCmdTimeOut, my_app_id ,GPlayerPlayCmdResponse) ;			
		 break;
		#endif
		#ifdef ZOOM_IN
	    case UOP_ZOOM_IN:
	 	   reduce_level++;
	 	   if(reduce_level>3)
	 		   reduce_level = 0;
	 	   AW_SetVideoZoomDown(reduce_level);
	 	   break;
		#endif
		case UOP_OSD:
			break;      
    }
    return ;
}

void AWGPlayerKeyProcess(AWMSG *pMsg)
{
    if((gplayer_processing_status == GPLAYER_STATUS_QUITTING) ||
       (gplayer_processing_status == GPLAYER_STATUS_SWITCHING)) { // no key responding during App quit processing
        return ;
    }
    AWGPlayerKeyDo(pMsg->msg_value) ;
}

INT32S audio_total_time;	
extern INT8U ChangeMp3Id3_Info_flag;
void AWGPlayerNotificationProcess(AWMSG *pMsg)
{
    PHWND hwnd ;
    PlaylistStatus_t status;
    PlaylistItem_t *item;
    INT8U my_app_id ;
    Playlist_t *playlist;
    INT32S total_time;
    char *p = NULL;
    char extname[5];
	
	switch(pMsg->msg_id){
		case NM_GET_AUDIO_TOTAL_TIME:
			total_time = pMsg->msg_value;
			audio_total_time=total_time;
			if(Music_Pic_mix_flag==0)
			{
				if(NODIR_FLAG == 0)
					FLgPlayerUpdateAudioTotalTime(audio_total_time);
				if(NODIR_FLAG == 1)
					gPlayerUpdateAudioTotalTime(audio_total_time);
			}



		   	break;
		   	
		case NM_UPDATE_SPECTRUM:
			if(Music_Pic_mix_flag==0)
			{
				if(Volume_Value==0)
				{
				   for(int i=0; i<32; i++)
				   	spectrum[i] = 0;
				}
				else
				{
				memcpy((void *)spectrum, (void *)pMsg->msg_value, 32*sizeof(int));  
				}
				if((NODIR_FLAG == 0)&&(gplayer_type == GPLAYER_AUDIO))
					FLUpdateSpectrumDisplay(spectrum); 
				if(NODIR_FLAG == 1)//&&(gplayer_type == GPLAYER_AUDIO))
					UpDateSpectrumDisplay(spectrum); 
			}
			break; 
		            
		case NM_GET_AUDIO_INFO:	
			break;
				
		case NM_GET_PLAYING_AUDIO_INFO:
			if ((gplayer_type == GPLAYER_AUDIO)&&((!(strcmp(file_info_onshow.file_type ,"MP3")))||(!(strcmp(file_info_onshow.file_type ,"WMA")))))
	   	 		Get_FileInfo(gCurOnlyMp3FileName);
			if((NODIR_FLAG == 0)&&(gplayer_type == GPLAYER_AUDIO) && (Music_Pic_mix_flag==0))
				FLgPlayerAppShowAudioID3Info();
			if((NODIR_FLAG == 1)&&(!(strcmp(file_info_onshow.file_type ,"MP3"))))//&&(gplayer_type == GPLAYER_AUDIO))
				gPlayerAppShowAudioID3Info();
            else if((NODIR_FLAG == 1)&&(!(strcmp(file_info_onshow.file_type ,"WMA"))))
				gAppShowVideoID3Info(gCurOnlyMp3FileName,AUDIO);
			break;	    
		
		case NM_END_OF_PLAY:
        #ifdef RESUME_PLAY
            if((gplayer_type == GPLAYER_VIDEO)&&(ResumePlayFlag == 1))
            {
                ResumePlayFlag = 0;
                AWGPLAYERQuitProcess();
	    		break;
            }
        #endif
			
			if(gplayer_processing_status != GPLAYER_STATUS_RUNNING) {
				break ;
			}

			if(pMsg->msg_value == GPLAYER_ERROR){
				if(gplayer_type == GPLAYER_VIDEO){
					if((preview_video != 1)&&((NODIR_FLAG == 0)||(NODIR_FLAG == 2))){
						ShowWinConfirm(CONFIRM_MOVIEPLAYBACK);
	    			}
	    			else {
	    				GetCurrUnSupportItemName();
	    				AWGPLAYERQuitProcess();
	    			}
	    		}
			}
			else if(preview_video == 1){
				send_gplayer_file(last_item_name);
			}
			else
        	{
    			if(!Music_Pic_mix_flag){  //evan:2007_11_9 modify
    				
    				if(gplayer_type == GPLAYER_AUDIO){
						if(GetMusicRepeatModePara() == (INT8U)0){
							if(NODIR_FLAG==0)
								AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_ONLYONE);
							else
								AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_REPEAT_ONE);
							}
						else if(GetMusicRepeatModePara() == 1){
							if(NODIR_FLAG==0)
								AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_ONLYONE);
							else
								AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_DIR_REPEAT);
							}
					}
					else {
						if(GetMovieRepeatModePara() == 0){
							if(NODIR_FLAG==0)
								AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_ONLYONE);
							else if(NODIR_FLAG==2)
								AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_REPEAT_ONE);
						}
						else 
						if(GetMovieRepeatModePara() == 1){
							if(NODIR_FLAG==0)
								AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_ONLYONE);
							else if(NODIR_FLAG==2)
								AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_DIR_REPEAT);
						}
					} // end of gplayer_type = GPLAYER_AUDIO
					
				} // end of Music_pic_mix_flag  
				else  //evan:2007_11_9modify
				{
					if(gplayer_type == GPLAYER_AUDIO)
					{
							if(GetMusicRepeatModePara() == (INT8U)0)
							{
								if(NODIR_FLAG==0)
									AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_REPEAT_ONE);
							}
							else if(GetMusicRepeatModePara() == 1)
							{
								if(NODIR_FLAG==0)
									AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_DIR_REPEAT);	
							}
					}
					else
					{
						if(GetMovieRepeatModePara() == 0)
						{
							if(NODIR_FLAG==0)

							AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_REPEAT_ONE);
						}
						else if(GetMovieRepeatModePara() == 1)
						{
							if(NODIR_FLAG==0)
								AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_DIR_REPEAT);
						}
					}
					
				}//evan:2007_11_9modify
//			}
				gplayer_processing_status = GPLAYER_STATUS_SKIPPING;
				status = AWGetNextPlaylistItem2(gplayer_playlist);
		
				if(status != PLAYLIST_STATUS_ASYNCH) {
					GPIO_MUTE ;
					AWGPLAYERQuitProcess();	
				}
				else {
					if((NODIR_FLAG == 1)&&(GetMusicRepeatModePara() == (INT8U)1)){
						UpdateIsProcessBarOnShowValue();
						FileListKeyDown();
					}
				}
			}
			break;

		case NM_UNSUPPORT_FORMAT:
				if(gplayer_type == GPLAYER_VIDEO){
					if((preview_video != 1)&&((NODIR_FLAG == 0)||(NODIR_FLAG == 2))){
						ShowWinConfirm(CONFIRM_MOVIEPLAYBACK);
/*						
						if(GetNextOrPrev == MANUAL_GET_PRE_CHAP){
							goto GET_PREV ;
						}
						else {
							goto GET_NEXT ;
						}
*/						
	    			}
	    			else {
	    				GetCurrUnSupportItemName();
	    				AWGPLAYERQuitProcess();
	    			}
	    		}
			break ;

		case NM_GET_NEXT:
GET_NEXT:
			if((gplayer_processing_status == GPLAYER_STATUS_QUITTING) ||
				(gplayer_processing_status == GPLAYER_STATUS_SWITCHING)) { // no key responding during App quit processing
				break ;
			}
			gplayer_processing_status = GPLAYER_STATUS_SKIPPING;
			if (GetMusicRepeatModePara() == 1){
				FileListKeyDown();
				status = AWGetNextPlaylistItem2(gplayer_playlist);
			}
			else if (GetMusicRepeatModePara() == 0) {
				status = AWGetNextPlaylistItem2(gplayer_playlist);
			}
			if(status != PLAYLIST_STATUS_ASYNCH) {
				GPIO_MUTE ;
				AWGPLAYERQuitProcess();	
			}
			break;
	        
		case NM_GET_PREV:
GET_PREV:			
			if((gplayer_processing_status == GPLAYER_STATUS_QUITTING) ||
				(gplayer_processing_status == GPLAYER_STATUS_SWITCHING)) { // no key responding during App quit processing
				break ;
			}
			gplayer_processing_status = GPLAYER_STATUS_SKIPPING;
			if (GetMusicRepeatModePara() == 1) {
//				FileListViewOnKeyPress_nodir(UOP_DOWN);
			}
			else if (GetMusicRepeatModePara() == 0) {
				status = AWGetPrevPlaylistItem2(gplayer_playlist);
			}		
			if(status != PLAYLIST_STATUS_ASYNCH) {
				GPIO_MUTE ;
				AWGPLAYERQuitProcess();
			}
			break;
	        
		case NM_PLAY_TIME_CHANGED:  
			
			if(Music_Pic_mix_flag==0)
	    		{
				if(gplayer_playing_time != pMsg->msg_value) {
					gplayer_playing_time = pMsg->msg_value ;

					if (pMsg->msg_value>audio_total_time) 
						pMsg->msg_value = audio_total_time;   
				}
				
				if( pMsg->msg_value == 0 ){
					ff_level = 1 ;
					fb_level = 1 ;
				}
				
				if((NODIR_FLAG == 0)&&(gplayer_type == GPLAYER_AUDIO))
					FLUpdateAudioProcessBar(audio_total_time, gplayer_playing_time);
				else if((NODIR_FLAG == 1)&&(gplayer_type == GPLAYER_AUDIO))
					UpdateAudioProcessBar(audio_total_time, gplayer_playing_time);
				else if(gplayer_type == GPLAYER_VIDEO)
				{
					gPlayerUpdateVideofPlayTime(gplayer_playing_time);
                }

			}
			
			if(GetNextOrPrev != NORMAL_GET_CHAP)
		        GetNextOrPrev = NORMAL_GET_CHAP;
		        
			break ;
	        
		case NM_SUBTITLE_TEXT:
			break;
			
		case NM_PLAY_STATUS_CHANGED:
			if (pMsg->msg_value == GPLAYER_PLAY) {
				AWGPlayerKeyDo(UOP_GETMP3INFO);
			}
			
			if(NODIR_FLAG == 0){//&&(gplayer_type == GPLAYER_AUDIO))
				if(gplayer_type == GPLAYER_VIDEO){
					gPlayerPlayState(4, pMsg->msg_id, pMsg->msg_value, ff_level, fb_level);
					}
				else{
					FLupdateAudioPlayStateWhenMsgProc(pMsg, ff_level, fb_level );
					}
				}
			else if(NODIR_FLAG == 1)//&&(gplayer_type == GPLAYER_AUDIO))
				updateAudioPlayStateWhenMsgProc(pMsg, ff_level, fb_level );
			else if((NODIR_FLAG == 2)&&(preview_video == 0))
				gPlayerPlayState(4, pMsg->msg_id, pMsg->msg_value, ff_level, fb_level);
			break ;
	        
	    case NM_PLAY_GPLAYER:
	    case NM_PLAY_GENERAL:       
	        if(!pMsg->msg_value) {
	            AWGPLAYERQuitProcess();
	            break;
	        }
	        playlist = (Playlist_t *)pMsg->msg_value;
	        AWUnLockPlaylist(playlist);
	        if(AWPlaylistIsInvalid(playlist)) {
	            if((INT32U)gplayer_playlist == (INT32U)playlist) {
	                gplayer_playlist = NULL;
	            }
	            AWPlaylistDelete2(playlist);
	            break ;
	        }
	        AWGetAppID(MEDIA_GENERAL, &my_app_id) ;
	        if (AWGetAppStatus(my_app_id) != APP_RUNNING) {
	            if (RunGPlayer(playlist)) {
	                AWPlaylistDelete2(playlist);
	                AWShowFileList(1);
	            }
	            else {
	                item = gplayer_playitem;
	                goto PLAY_GPLAYER_FILE;
	            }
	        }
	        else {
	            item = AWGetCurrentPlaylistItem2(playlist);
PLAY_GPLAYER_FILE:
	            if(item) {
      		    #ifdef RESUME_PLAY
                    if((gplayer_type == GPLAYER_VIDEO)&&(preview_video == 0)&&(ResumeFunction == 1))
    			    {
        			  	memset(resume_file.file_name,0,100);
        				strcpy(resume_file.file_name,item->location);
        				SetResumeFilePara(resume_file.file_name);
        				resume_file.time = 0;
        				SetResumeTimePara(resume_file.time); 
            		#if RESUME_INTERVAL_TIME
            			SetResumePlayFlagPara(1);
            	    #else
            			SetResumePlayFlagPara(0);
            	    #endif
    			    }
			    #endif
		            p = strrchr(item->location, '/');		
	                sprintf(gCurOnlyMp3FileName,"%s",p+1);
			  #ifdef ZOOM_IN
				reduce_level = 0;
			  #endif
			  #ifdef TIME_SEARCH
			  Get_FileInfo(gCurOnlyMp3FileName);
			  #endif
			if((NODIR_FLAG == 0)&&(gplayer_type == GPLAYER_AUDIO)){
	  			hwnd = AWFindWinCtrlByName(WinFileListProcessBar);
	  			if(hwnd)
	  			AWShowWinControl(hwnd, 0) ;
				}
	                gplayer_playing_time = -1;
	                ff_level = fb_level = 1 ;
	                if(gplayer_processing_status == GPLAYER_STATUS_SKIPPING) {
	                    gplayer_processing_status = GPLAYER_STATUS_RUNNING;
	                }
	                send_gplayer_file(item->location);
	            } else {
	                AWGPLAYERQuitProcess();
	            }
	        }
	        break ;
    }

    return ;
}

void AWGPLAYERBroadCastProcess(AWMSG* pMsg)
{
	CHARSTR* temp;
	if(pMsg->msg_id==BM_DEVICE_PRE_UNMOUNT)
	{
		temp=((DEV_MOUNT_INFO *)(pMsg->msg_value))->mount_point_name;

    #ifdef RESUME_PLAY
        if(ResumePlayFlag == 1)
        {
		    if (strncmp(resume_file.file_name, temp, 5) == 0)
		    {
                SetForceCloseMediaApp();
                device_removed=1; // move this line before "AWGPlayerKeyDo(UOP_STOP)" because device_removed will be used during call AWGPlayerKeyDo
                preview_video=0;
                AWGPLAYERQuitProcess();
            }
		}
		else
    #endif
        {
            if (strncmp(GPlayerGetCurrentPlayingName(), temp, strlen(temp)) == 0) 
    		{
    			SetForceCloseMediaApp();
    			device_removed=1; // move this line before "AWGPlayerKeyDo(UOP_STOP)" because device_removed will be used during call AWGPlayerKeyDo
    			preview_video=0;
    			AWGPLAYERQuitProcess();
    		}
		} 
	}        
}    

void AWGPLAYERMsgProcess(AWMSG *pMsg)
{
    switch(pMsg->msg_type){
    case MSG_INPUT_EVENT:
        if(pMsg->msg_id == WM_KEYDOWN)
            AWGPlayerKeyProcess(pMsg) ;
        break ;
    case MSG_NOTIFICATION:
        AWGPlayerNotificationProcess(pMsg) ;
        break ;
    case MSG_QUIT:
        AWGPLAYERQuitProcess2(pMsg) ;
        break;
    case MSG_BROADCAST:
        AWGPLAYERBroadCastProcess(pMsg) ;
        break;
    default:
        break ;
    }
    return ;
}

int RunGPlayer_loop(Playlist_t *playlist)
{
    int r = 0;
    INT8U my_app_id ;
    INT32U item_type;

    if(gplayer_playlist) {
        if(AWPlaylistDelete2(gplayer_playlist) == 0) {
            gplayer_playlist = NULL;
        }
    }

    AWGetAppID(MEDIA_GENERAL, &my_app_id) ; 
    if (AWGetAppStatus(my_app_id) != APP_RUNNING) {
        AWSetPlaylistAppCb(playlist, GPlayerPlaylistCb);
        gplayer_playlist = playlist;
        if((gplayer_playitem = AWGetCurrentPlaylistItem2(playlist)) == NULL) {
            if(AWGetStartPlaylistItem2(playlist) != PLAYLIST_STATUS_ASYNCH) {
                gplayer_playlist = NULL;
                return -1 ;
            }
        }
        String_Init_Time();

        item_type = GetMediaType(gplayer_playlist->cur_play_item->item.location) ;
        if (item_type&AW_AUDIO_LIST){
            gplayer_type = GPLAYER_AUDIO;
        }
        else if (item_type == MEDIA_MOV)
            gplayer_type = GPLAYER_VIDEO;
        else
            gplayer_type = GPLAYER_UNKNOW;

        if ((gplayer_type == GPLAYER_VIDEO) && (preview_video == 0))
            ShowWinMoviePlayBack();

        AWAppRunning(my_app_id) ;
        gplayer_processing_status = GPLAYER_STATUS_RUNNING;
    } else {
        send_gplayer_quit();
        gplayer_playlist = NULL;
        return -1;
    }
    
	
			AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_DIR_REPEAT);
		

    return 0;
}	

void disable_video_layer(void)
{
	int video_fd;
	video_fd=open("/dev/video",O_RDONLY);
	ioctl(video_fd, VIDEOIO_DISABLE, 0);
	close(video_fd);
}

#ifdef ENABLE_BLUETOOTH
void AudioPlayer(char *filename)
{
	INT8U my_app_id ;

	bt_play_flag = 1;
	AWGetAppID(MEDIA_GENERAL, &my_app_id) ; 
	if (AWGetAppStatus(my_app_id) != APP_RUNNING) {
		AWAppRunning(my_app_id) ;
              String_Init_Time();
             gplayer_processing_status = GPLAYER_STATUS_RUNNING;
	}
	strcpy(gCurOnlyMp3FileName,filename);
	send_gplayer_file(gCurOnlyMp3FileName);
#ifdef USE_NEW_SCREEN_SAVER 
    ScrSaverSet(SCREEN_SAVER_OFF) ;
    ScrSaverReset() ;
#endif
	GUIShowWindow("WinMp3InfoBar") ;
       AWSetPlaylistPlayMode2(gplayer_playlist, PLAY_MODE_DIR_REPEAT);
}

#endif

